><

Setting up JavaScript



You can add JavaScripts to your document page. You can also insert JavaScripts in the head section of your document window to allow a script to be executed while the visible section of the document is still being loaded. After you have inserted an icon in the body or head of your Web page, you create the JavaScript in the JavaScript Editor.

To set up a JavaScript:

1 Drag the JavaScript icon from the Basic tab () of the Objects palette to your document window, drag the Script icon from the Head tab () of the Objects palette to the head section pane, or select the Java-Script Editor icon () in the upper right of the document window and click the New Script Item button () on the toolbar of the resulting JavaScript Editor window.


A. JavaScript icon B. Script icon

2 Select the JavaScript icon in the document window, or select the Script icon in the head section pane.

3 In the Inspector, type in a descriptive name in the Name text box.

4 Choose a target browser from the Language pop-up menu. The language version corresponding to your browser selection appears in the text box below the menu.

5 To reference an existing script, select Source and type in a resource locator for your script file, click the Browse button to select a script, or drag from the Point and Shoot button to link to a script in the site window. Script files must have the .js extension.

To edit an existing JavaScript:

1 To open the JavaScript Editor, do one of the following:

  • Double-click the JavaScript icon in the document window.
  • Select the JavaScript icon in the document window, and click the Edit button in the Inspector.
  • Click the JavaScript Editor icon () in the upper right of the document window.

  • 2 If the icons on the JavaScript Editor toolbar are inactive, click New Script Item () button.

    3 Click the Events tab of the JavaScript Inspector to see the objects that can have events attached and the events they support. To add an event to your script, select the event in the Inspector, and type the event code in the Event Code text box.


    Create event definitions by typing the event codes in the Event Code text box.

    4 Click the Objects tab of the JavaScript Inspector to display the complete inventory of JavaScript objects. To add an object to your script, drag it from the Objects tab to the JavaScript Editor window.

    Click a function declaration in the Functions list in the Script tab of the JavaScript Inspector window to navigate directly to that location in the script.

    5 Close the JavaScript Editor to save your work.

    6 Click Show in Browser on the Adobe GoLive toolbar to open your Web page in the browser you selected for previewing and testing in the Preferences dialog box. Or choose Special > Show in Default Browser.

    Note: In Mac OS, you cannot preview the effects of a JavaScript in Preview mode.

    The following sample JavaScript code shows how to use a simple JavaScript to display the time and date obtained from the viewer's operating system.


    JavaScript sample

  • The document.write() method on the "Your Local Time" line writes an H1-formatted text string from the document to the screen of the browser.
  • new Date()creates a new date object containing the long version of the current date from the viewer's operating system. This object is assigned to currtime.
  • The last line is output again to the browser's screen using a document.write() method, with the embedded currtime variable set to the current time and date.


  • Adding Interactivity > Using JavaScript > Setting up JavaScript